
#include <iostream>
#include "surface.h"

using namespace std;

Surface :: Surface (){};

SDL_Surface* Surface :: Load (char* Filename) {
  SDL_Surface* Surf_tmp = NULL;
  SDL_Surface* Surf_return = NULL;
  
  if ((Surf_tmp = SDL_LoadBMP(Filename)) == NULL) {
    cout << "ERROR: in Surface::Load" << endl;
    cout << "ERROR: Couldn't load file" << endl;
    return NULL;
  }
  
  Surf_return = SDL_DisplayFormat(Surf_tmp);
  SDL_FreeSurface(Surf_tmp);
  
  return Surf_return;
};

bool Surface :: Draw (SDL_Surface* Surf_Src, SDL_Surface* Surf_Dest, int dstX, int dstY) {
  if (Surf_Dest == NULL || Surf_Src == NULL) {
    cout << "ERROR: in Surface::Draw" << endl;
    cout << "ERROR: Dest or Src surface is NULL" << endl;
    return false;
  };
  
  SDL_Rect DestRect;
  
  DestRect.x = dstX;
  DestRect.y = dstY;
  
  SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestRect);
  
  return true;
};

bool Surface :: Draw (SDL_Surface* Surf_Src, int srcX, int srcY, int srcW, int srcH, SDL_Surface* Surf_Dest, int dstX, int dstY) {
  if (Surf_Dest == NULL || Surf_Src == NULL) {
    cout << "ERROR: in Surface::Draw" << endl;
    cout << "ERROR: Dest or Src surface is NULL" << endl;
    return false;
  };
  
  SDL_Rect DestRect;
  
  DestRect.x = dstX;
  DestRect.y = dstY;
  
  SDL_Rect SrcRect;
  
  SrcRect.x = srcX;
  SrcRect.y = srcY;
  SrcRect.w = srcW;
  SrcRect.h = srcH;
  
  SDL_BlitSurface(Surf_Src, &SrcRect, Surf_Dest, &DestRect);
  
  return true;
  
};

bool Surface :: SetTransparent(SDL_Surface* Surf_Dest, int R, int G, int B){
  if(Surf_Dest == NULL){
    return false;
  }
  
  SDL_SetColorKey(Surf_Dest, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surf_Dest->format, R, G, B));
  
  return true;
};

